﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Linq;
using WPFExcelReport.Helpers;
using System.Windows.Input;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// 专用于布卷剪布
    /// </summary>
    public partial class TWB4X
    {  
        public TWB4X()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWBBST();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
            Load();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwWB = dwMaster;
            if (dwWB == null)
                return;
            RWAUF = dwWB["WBBRWKRS"].ToString() + dwWB["WBBRWLFD"].ToString();
        }
        public void Load()
        { 
            if (STKNR.Length < 1)
            {
                TBMain.Clear();
                return;
            }
            if (TBMain == null)
                return;
            dwData = TBMain.NewRow();
            dwData["WBBMANDANT"] = app.Mandant;
            dwData["WBBSTKNR"] = STKNR.PadRight(12);
            SResult = TMV.QueryWBBST(dwData, 13);
            MergeData(SResult, true);
        }
        

        public override void NewCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (txtCUT.Text == "N")
            {
                MessageBox.Show("请手工将标志改为Y");
                return;
            }
            if (dwWB == null)
                return;
            if (dwWB["WBBAUFLFD"].ToString() != "000000")
            {
                MessageBox.Show("已经被留位，需要先取消留位");
                return;
            }
            txtCUT.Text = "N";

            TMV.CHGQTY(dwWB, CMTR);
            base.NewCommand(sender, e);
        }

        public void Update(DataRow _dWB)
        {
            if (_dWB == null)
                return;
         
            TMV.UpdateWBBST(_dWB, 0);
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            Load();
            base.QueryCommand(sender, e);
        }
    }
}
